// 中奖信息相关内容：使用按钮，分享按钮，奖品信息
function showPrizeRelation()
{
  $('.js_scatchWinBox').show();
  $('.js_useBox').show();
  $('.js_shareBox').show();
  resizeFrame();
}

$(function(){
  //判断是否已中奖
  if (1 == snType) {
      //显示中奖结果
      $('#wScratchPad').css({ "background-image" : "url('"+scatchImg+"')" });
      //判断是否中奖
      if (scatchWin != 0) {
        showPrizeRelation();
      }
      return;
  } 
  
  if (0 == isAblePlay){
      //不可以再刮
      $('#wScratchPad').css({ "background-image" : "url('"+scatchImg+"')" });
      
  }  else if (isAblePlay>=1) {
     // 刮刮卡 今天可以刮
      //判断是否已中过奖
      // 还可以继续刮
        var sp = $("#wScratchPad").wScratchPad({
            scratchDown: function(){
              $(this.canvas).css('margin-right', $(this.canvas).css('margin-right') == "0px" ? "1px" : "0px");
            },
            scratchMove: function(){
              $(this.canvas).css('margin-right', $(this.canvas).css('margin-right') == "0px" ? "1px" : "0px");
            },
            scratchUp: function(e, percent){
              $(this.canvas).css('margin-right', $(this.canvas).css('margin-right') == "0px" ? "1px" : "0px");
              
              if (percent > 0 && !isScatch) {
                isScatch = true;
                var postData = {
                    'user_info_id'       : userInfoId
                };
                $.ajax(
                        {
                            type: "post",
                            url: saveRecordInfoUrl,
                            dataType: "text",
                            data: postData,
                            async:false,
                            success: function(json) {
                            	var json = eval("(" + json + ")");
                            	if (json.status == 2) {
                              	  alert("服务器错误");
                              	  sp.wScratchPad('reset');
                                }else if (json.status == 0) {
                              	  alert("用户信息不存在");
                                    sp.wScratchPad('reset');
                               }
                                $('#js_alreadyNum').text(json.already_times);
                            }
                 });
              }
              if (percent > 20) {
                $('#wScratchPad').css({ "background-image" : "url('"+scatchImg+"')" });
                var showMess = '';
                if (scatchWin != 0) {
                  showMess = '恭喜您中了';
                  if (scatchWin == 1) {
                    showMess += '一';
                  } else if (scatchWin == 2) {
                    showMess += '二';
                  } else if (scatchWin == 3) {
                    showMess += '三';
                  } else if (scatchWin == 4) {
                    showMess += '四';
                  } else if (scatchWin == 5) {
                    showMess += '五';
                  } else if (scatchWin == 6) {
                    showMess += '六';
                  }
                  showMess += '等奖';
                } else {
                   showMess = '谢谢参与';
                }
                if (!isShowMsg) {
                  isShowMsg = true;
                }
                
                // 中奖后，显示中奖信息，显示分享，显示立即使用，重新计算高度
                if (scatchWin != 0) {
                  showPrizeRelation();
                }
              }
            },
            width           : 163,                  // set width - best to match image width
            height          : 43,                  // set height - best to match image height
            image           : scatchImg,  // set image path
            image2          : siteUrl+'/frontend/default/activity/scratchcard/img/scratch_pad.png',                 // set overlay image path - if set color is not used
            color           : '#336699',            // set scratch color - if image2 is not set uses color
            overlay         : 'none',               // set the type of overlay effect 'none', 'lighter' - only used with color
            size            : 10,                   // set size of scratcher
            realtimePercent : false,                // Update scratch percent only on the mouseup/touchend (for better performances on mobile device)
            cursor          : null 
          });

  }
})